package com.ygp.asyn.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sun.istack.internal.NotNull;
import com.ygp.asyn.entity.HttpRes;
import com.ygp.asyn.entity.TimeOutOption;
import com.ygp.asyn.enums.HttpParseEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.*;

@Slf4j
public class HttpUtil {


    private final static String SUCCESS = "success";
    private final static String OBJ = "obj";
    private final static String RESULT = "result";

    private final static String EMPTY_BODY = JSON.toJSONString(new HashMap<>());


    // 默认从连接池获取连接时间
    private final static Integer CONNECT_TIMEOUT = 500;
    // 读取数据获取超时时间
    private final static Integer SOCKET_TIMEOUT = 15000;

    private final static String UTF8 = "UTF-8";


    public static String executePost(String url, String reqBody, boolean isPick) {
        return null;
    }

    public static String executePost(String url, String reqBody, boolean isPick, TimeOutOption timeOutOption) {

        return null;
    }


    public static <T> T executePostObj(String url, String reqBody, Class<T> clazz) {
        T t = null;
        try {
            String re = executePost(url, reqBody, true);
            if (StringUtils.isBlank(re)) {
                return null;
            }
            t = JSON.parseObject(re, clazz);
        } catch (Exception e) {
            log.error("executePostObj error url:{} param:{} error:", url, reqBody, e);
        }
        return t;
    }


    public static <T> T executePostObj(String url, String reqBody, Class<T> clazz, TimeOutOption timeOutOption) {
        String re = executePost(url, reqBody, true, timeOutOption);
        if (StringUtils.isBlank(re)) {
            return null;
        }
        T t = null;
        try {
            t = JSON.parseObject(re, clazz);
        } catch (Exception e) {
            log.error("executePostObj error url:{} param:{} error:", url, reqBody, e);
        }
        return t;
    }


    public static <T> T postObj(String url, Map<String, String> head, Object reqBody, @NotNull Class<T> clazz, TimeOutOption timeOutOption) {
        return null;
    }


    public static <T> T postObjForm(String url, Map<String, String> head, Object reqBody, @NotNull Class<T> clazz) {
        return null;
    }
    

    public static <T> T postObj(String url, Map<String, String> head, Object reqBody, @NotNull Class<T> clazz) {
        return postObj(url, head, reqBody, clazz, getTimeOut(500,500));
    }

    public static <T> T postObj(String url, Object reqBody, @NotNull Class<T> clazz, TimeOutOption timeOutOption) {
        return postObj(url, null, reqBody, clazz, timeOutOption);
    }

    public static <T> T postObj(String url, Object reqBody, @NotNull Class<T> clazz) {
        return postObj(url, null, reqBody, clazz, getTimeOut(500,500));
    }


    public static <T> T postObj(String url, Map<String, String> head, Object reqBody, @NotNull Class<T> clazz, TimeOutOption timeOutOption, String judgeField, String judgeValue, String dataField) {
        JSONObject re = postJSONObject(url, head, reqBody, timeOutOption);
        return parseReObj(re, clazz, judgeField, judgeValue, dataField);
    }

    public static <T> T postObj(String url, Map<String, String> head, Object reqBody, @NotNull Class<T> clazz, String judgeField, String judgeValue, String dataField) {
        JSONObject re = postJSONObject(url, head, reqBody);
        return parseReObj(re, clazz, judgeField, judgeValue, dataField);
    }

    public static <T> T postObj(String url, Object reqBody, @NotNull Class<T> clazz, TimeOutOption timeOutOption, String judgeField, String judgeValue, String dataField) {
        JSONObject re = postJSONObject(url, reqBody, timeOutOption);
        return parseReObj(re, clazz, judgeField, judgeValue, dataField);
    }

    public static <T> T postObj(String url, Object reqBody, @NotNull Class<T> clazz, String judgeField, String judgeValue, String dataField) {
        JSONObject re = postJSONObject(url, reqBody);
        return parseReObj(re, clazz, judgeField, judgeValue, dataField);
    }

    public static <T> T postObj(String url, Map<String, String> head, Object reqBody, @NotNull Class<T> clazz, TimeOutOption timeOutOption, HttpParseEnum parseEnum) {
        JSONObject re = postJSONObject(url, head, reqBody, timeOutOption);
        return parseReObj(re, clazz, parseEnum);
    }

    public static <T> T postObj(String url, Map<String, String> head, Object reqBody, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        JSONObject re = postJSONObject(url, head, reqBody);
        return parseReObj(re, clazz, parseEnum);
    }

    public static <T> T postObjForm(String url, Map<String, String> head, Object reqBody, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        JSONObject re = postObjForm(url, head, reqBody, JSONObject.class);
        return parseReObj(re, clazz, parseEnum);
    }

    public static <T> T postObj(String url, Object reqBody, @NotNull Class<T> clazz, TimeOutOption timeOutOption, HttpParseEnum parseEnum) {
        JSONObject re = postJSONObject(url, reqBody, timeOutOption);
        return parseReObj(re, clazz, parseEnum);
    }

    public static <T> T postObj(String url, Object reqBody, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        JSONObject re = postJSONObject(url, reqBody);
        return parseReObj(re, clazz, parseEnum);
    }


    public static <T> List<T> postList(String url, Map<String, String> head, Object reqBody, @NotNull Class<T> clazz, TimeOutOption timeOutOption) {
        return Collections.emptyList();
    }

    public static <T> HttpRes<T> postListFormMsg(String url, Map<String, String> head, Object reqBody, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        JSONObject re = postObjForm(url, head, reqBody, JSONObject.class);
        return parseReListMsg(re, clazz, parseEnum);
    }

    public static <T> List<T> postList(String url, Map<String, String> head, Object reqBody, @NotNull Class<T> clazz) {
        return postList(url, head, reqBody, clazz, getTimeOut(500,500));
    }


    public static <T> List<T> postList(String url, Object reqBody, @NotNull Class<T> clazz, TimeOutOption timeOutOption) {
        return postList(url, null, reqBody, clazz, timeOutOption);
    }

    public static <T> List<T> postList(String url, Object reqBody, @NotNull Class<T> clazz) {
        return postList(url, null, reqBody, clazz, getTimeOut(500,500));
    }


    public static <T> List<T> postList(String url, Map<String, String> head, Object reqBody, @NotNull Class<T> clazz, TimeOutOption timeOutOption, String judgeField, String judgeValue, String dataField) {
        JSONObject re = postJSONObject(url, head, reqBody, timeOutOption);
        return parseReList(re, clazz, judgeField, judgeValue, dataField);
    }

    public static <T> List<T> postList(String url, Map<String, String> head, Object reqBody, @NotNull Class<T> clazz, String judgeField, String judgeValue, String dataField) {
        JSONObject re = postJSONObject(url, head, reqBody);
        return parseReList(re, clazz, judgeField, judgeValue, dataField);
    }

    public static <T> List<T> postList(String url, Object reqBody, @NotNull Class<T> clazz, TimeOutOption timeOutOption, String judgeField, String judgeValue, String dataField) {
        JSONObject re = postJSONObject(url, reqBody, timeOutOption);
        return parseReList(re, clazz, judgeField, judgeValue, dataField);
    }

    public static <T> List<T> postList(String url, Object reqBody, @NotNull Class<T> clazz, String judgeField, String judgeValue, String dataField) {
        JSONObject re = postJSONObject(url, reqBody);
        return parseReList(re, clazz, judgeField, judgeValue, dataField);
    }


    public static <T> List<T> postList(String url, Map<String, String> head, Object reqBody, @NotNull Class<T> clazz, TimeOutOption timeOutOption, HttpParseEnum parseEnum) {
        JSONObject re = postJSONObject(url, head, reqBody, timeOutOption);
        return parseReList(re, clazz, parseEnum);
    }

    public static <T> List<T> postList(String url, Map<String, String> head, Object reqBody, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        JSONObject re = postJSONObject(url, head, reqBody);
        return parseReList(re, clazz, parseEnum);
    }

    public static <T> HttpRes<T> postListMsg(String url, Map<String, String> head, Object reqBody, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        JSONObject re = postJSONObject(url, head, reqBody);
        return parseReListMsg(re, clazz, parseEnum);
    }

    public static <T> List<T> postList(String url, Object reqBody, @NotNull Class<T> clazz, TimeOutOption timeOutOption, HttpParseEnum parseEnum) {
        JSONObject re = postJSONObject(url, reqBody, timeOutOption);
        return parseReList(re, clazz, parseEnum);
    }

    public static <T> List<T> postList(String url, Object reqBody, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        JSONObject re = postJSONObject(url, reqBody);
        return parseReList(re, clazz, parseEnum);
    }

    public static <T> HttpRes<T> postListMsg(String url, Object reqBody, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        JSONObject re = postJSONObject(url, reqBody);
        return parseReListMsg(re, clazz, parseEnum);
    }


    public static JSONObject postJSONObject(String url, Map<String, String> head, Object reqBody, TimeOutOption timeOutOption) {
        return postObj(url, head, reqBody, JSONObject.class, timeOutOption);
    }

    public static JSONObject postJSONObject(String url, Map<String, String> head, Object reqBody) {
        return postObj(url, head, reqBody, JSONObject.class, getTimeOut(500,500));
    }

    public static JSONObject postJSONObject(String url, Object reqBody, TimeOutOption timeOutOption) {
        return postObj(url, null, reqBody, JSONObject.class, timeOutOption);
    }

    public static JSONObject postJSONObject(String url, Object reqBody) {
        return postObj(url, null, reqBody, JSONObject.class, getTimeOut(500,500));
    }


    public static String postStr(String url, Map<String, String> head, Object reqBody, TimeOutOption timeOutOption) {
        return null;
    }

    public static String postStr(String url, Map<String, String> head, Object reqBody) {
        return postStr(url, head, reqBody, getTimeOut(500,500));
    }

    public static String postStr(String url, Object reqBody, TimeOutOption timeOutOption) {
        return postStr(url, null, reqBody, timeOutOption);
    }

    public static String postStr(String url, Object reqBody) {
        return postStr(url, null, reqBody, getTimeOut(500,500));
    }

    //==================================get===========================================================//
    public static <T> T getObj(String url, Map<String, String> head, Object params, @NotNull Class<T> clazz, TimeOutOption timeOutOption) {
        return null;
    }

    public static <T> T getObj(String url, Map<String, String> head, JSONObject param, @NotNull Class<T> clazz) {
        return null;
    }


    public static <T> T getObj(String url, Map<String, String> head, Object params, @NotNull Class<T> clazz) {
        return getObj(url, head, params, clazz, getTimeOut(500,500));
    }

    public static <T> T getObj(String url, Object params, @NotNull Class<T> clazz, TimeOutOption timeOutOption) {
        return getObj(url, null, params, clazz, timeOutOption);
    }

    public static <T> T getObj(String url, Object params, @NotNull Class<T> clazz) {
        return getObj(url, null, params, clazz, getTimeOut(500,500));
    }


    public static <T> T getObj(String url, Map<String, String> head, Object params, @NotNull Class<T> clazz, TimeOutOption timeOutOption, String judgeField, String judgeValue, String dataField) {
        JSONObject re = getJSONObject(url, head, params, timeOutOption);
        return parseReObj(re, clazz, judgeField, judgeValue, dataField);
    }

    public static <T> T getObj(String url, Map<String, String> head, Object params, @NotNull Class<T> clazz, String judgeField, String judgeValue, String dataField) {
        JSONObject re = getJSONObject(url, head, params);
        return parseReObj(re, clazz, judgeField, judgeValue, dataField);
    }

    public static <T> T getObj(String url, Object params, @NotNull Class<T> clazz, TimeOutOption timeOutOption, String judgeField, String judgeValue, String dataField) {
        JSONObject re = getJSONObject(url, params, timeOutOption);
        return parseReObj(re, clazz, judgeField, judgeValue, dataField);
    }

    public static <T> T getObj(String url, Object params, @NotNull Class<T> clazz, String judgeField, String judgeValue, String dataField) {
        JSONObject re = getJSONObject(url, params);
        return parseReObj(re, clazz, judgeField, judgeValue, dataField);
    }


    public static <T> T getObj(String url, Map<String, String> head, Object params, @NotNull Class<T> clazz, TimeOutOption timeOutOption, HttpParseEnum parseEnum) {
        JSONObject re = getJSONObject(url, head, params, timeOutOption);
        return parseReObj(re, clazz, parseEnum);
    }

    public static <T> T getObj(String url, Map<String, String> head, Object params, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        JSONObject re = getJSONObject(url, head, params);
        return parseReObj(re, clazz, parseEnum);
    }

    public static <T> T getObj(String url, Map<String, String> head, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        JSONObject re = getJSONObject(url, head, new HashMap<>(0));
        return parseReObj(re, clazz, parseEnum);
    }

    public static <T> HttpRes<T> getObjMsg(String url, Map<String, String> head, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        JSONObject re = getJSONObject(url, head, new HashMap<>(0));
        return parseReObjMsg(re, clazz, parseEnum);
    }

    public static <T> HttpRes<T> getObjMsg(String url, Map<String, String> head, Object params, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        JSONObject re = getJSONObject(url, head, params);
        return parseReObjMsg(re, clazz, parseEnum);
    }

    public static <T> T getObj(String url, Object params, @NotNull Class<T> clazz, TimeOutOption timeOutOption, HttpParseEnum parseEnum) {
        JSONObject re = getJSONObject(url, params, timeOutOption);
        return parseReObj(re, clazz, parseEnum);
    }

    public static <T> T getObj(String url, Object params, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        JSONObject re = getJSONObject(url, params);
        return parseReObj(re, clazz, parseEnum);
    }


    public static <T> List<T> getList(String url, Map<String, String> head, Object params, @NotNull Class<T> clazz, TimeOutOption timeOutOption) {
        return Collections.emptyList();
    }

    public static <T> List<T> getList(String url, Map<String, String> head, Object params, @NotNull Class<T> clazz) {
        return getList(url, head, params, clazz, getTimeOut(500,500));
    }

    public static <T> List<T> getList(String url, Map<String, String> head, @NotNull Class<T> clazz) {
        return getList(url, head, new HashMap<>(0), clazz, getTimeOut(500,500));
    }

    public static <T> List<T> getList(String url, Object params, @NotNull Class<T> clazz, TimeOutOption timeOutOption) {
        return getList(url, null, params, clazz, timeOutOption);
    }

    public static <T> List<T> getList(String url, Object params, @NotNull Class<T> clazz) {
        return getList(url, null, params, clazz, getTimeOut(500,500));
    }


    public static <T> List<T> getList(String url, Map<String, String> head, Object params, @NotNull Class<T> clazz, TimeOutOption timeOutOption, String judgeField, String judgeValue, String dataField) {
        JSONObject re = getJSONObject(url, head, params, timeOutOption);
        return parseReList(re, clazz, judgeField, judgeValue, dataField);
    }

    public static <T> List<T> getList(String url, Map<String, String> head, Object params, @NotNull Class<T> clazz, String judgeField, String judgeValue, String dataField) {
        JSONObject re = getJSONObject(url, head, params);
        return parseReList(re, clazz, judgeField, judgeValue, dataField);
    }

    public static <T> List<T> getList(String url, Object params, @NotNull Class<T> clazz, TimeOutOption timeOutOption, String judgeField, String judgeValue, String dataField) {
        JSONObject re = getJSONObject(url, params, timeOutOption);
        return parseReList(re, clazz, judgeField, judgeValue, dataField);
    }

    public static <T> List<T> getList(String url, Object params, @NotNull Class<T> clazz, String judgeField, String judgeValue, String dataField) {
        JSONObject re = getJSONObject(url, params);
        return parseReList(re, clazz, judgeField, judgeValue, dataField);
    }


    public static <T> List<T> getList(String url, Map<String, String> head, Object params, @NotNull Class<T> clazz, TimeOutOption timeOutOption, HttpParseEnum parseEnum) {
        JSONObject re = getJSONObject(url, head, params, timeOutOption);
        return parseReList(re, clazz, parseEnum);
    }

    public static <T> List<T> getList(String url, Map<String, String> head, Object params, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        JSONObject re = getJSONObject(url, head, params);
        return parseReList(re, clazz, parseEnum);
    }

    public static <T> List<T> getList(String url, Map<String, String> head, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        JSONObject re = getJSONObject(url, head, new HashMap<>(0));
        return parseReList(re, clazz, parseEnum);
    }

    public static <T> List<T> getList(String url, Object params, @NotNull Class<T> clazz, TimeOutOption timeOutOption, HttpParseEnum parseEnum) {
        JSONObject re = getJSONObject(url, params, timeOutOption);
        return parseReList(re, clazz, parseEnum);
    }

    public static <T> List<T> getList(String url, Object params, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        JSONObject re = getJSONObject(url, params);
        return parseReList(re, clazz, parseEnum);
    }

    public static <T> HttpRes<T> getListMsg(String url, Map<String, String> head, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        JSONObject re = getJSONObject(url, head, new HashMap<>(0));
        return parseReListMsg(re, clazz, parseEnum);
    }

    public static <T> HttpRes<T> getListMsg(String url, Map<String, String> head, Object params, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        JSONObject re = getJSONObject(url, head, params);
        return parseReListMsg(re, clazz, parseEnum);
    }


    public static JSONObject getJSONObject(String url, Map<String, String> head, Object params, TimeOutOption timeOutOption) {
        return getObj(url, head, params, JSONObject.class, timeOutOption);
    }

    public static JSONObject getJSONObject(String url, Map<String, String> head, Object params) {
        return getObj(url, head, params, JSONObject.class, getTimeOut(500,500));
    }

    public static JSONObject getJSONObject(String url, Object params, TimeOutOption timeOutOption) {
        return getObj(url, null, params, JSONObject.class, timeOutOption);
    }

    public static JSONObject getJSONObject(String url, Object params) {
        return getObj(url, null, params, JSONObject.class, getTimeOut(500,500));
    }

    public static String getStr(String url, Map<String, String> head, Object params, TimeOutOption timeOutOption) {
        return null;
    }

    public static String getStr(String url, Map<String, String> head, Object params) {
        return getStr(url, head, params, getTimeOut(500,500));
    }

    public static String getStr(String url, Object params, TimeOutOption timeOutOption) {
        return getStr(url, null, params, timeOutOption);
    }

    public static String getStr(String url, Object params) {
        return getStr(url, null, params, getTimeOut(500,500));
    }

    public static <T> List<T> executePostList(String url, String reqBody, Class<T> clazz) {
        String re = executePost(url, reqBody, true);
        if (StringUtils.isBlank(re)) {
            return Collections.emptyList();
        }
        List<T> t = Collections.emptyList();
        try {
            t = JSON.parseObject(re, JSONArray.class).toJavaList(clazz);
        } catch (Exception e) {
            log.error("executePostList error url:{} param:{} error:", url, reqBody, e);
        }
        return t;
    }

    /**
     * 获取请求头
     *
     * @param head ；
     * @return ；
     */
    private static Map<String, String> getHead(Map<String, String> head) {
        return head;
    }
    

    public static TimeOutOption getTimeOut(Integer connectTimeOut, Integer socketTimeOut) {
        return new TimeOutOption(connectTimeOut, socketTimeOut);
    }


    private static <T> T parseReObj(JSONObject re, @NotNull Class<T> clazz, String judgeField, @NotNull String judgeValue, String dataField) {
        if (re == null || (judgeValue != null && !judgeValue.equals(re.getString(judgeField))) || re.get(dataField) == null) {
            return null;
        }
        try {
            return re.getObject(dataField, clazz);
        } catch (Exception e) {
            log.error("parseReObj fail re:{} dataField:{} error:", re, dataField, e);
        }
        return null;
    }

    private static <T> T parseReObj(JSONObject re, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        if (re == null || (parseEnum.getJudgeValue() != null && !parseEnum.getJudgeValue().equals(re.getString(parseEnum.getJudgeField())))) {
            return null;
        }
        try {
            String[] dataField = parseEnum.getDataField();
            JSONObject result = re;
            for (int i = 0; i < dataField.length; i++) {
                if (i == dataField.length - 1) {
                    return result.getObject(dataField[i], clazz);
                } else {
                    result = result.getJSONObject(dataField[i]);
                }
                if (result == null) {
                    break;
                }
            }
        } catch (Exception e) {
            log.error("parseReObj fail re:{} dataField:{} error:", re, parseEnum.getDataField(), e);
        }
        return null;
    }

    private static <T> HttpRes<T> parseReObjMsg(JSONObject re, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        HttpRes<T> res = new HttpRes<>();
        if (re == null) {
            return res;
        }
        if ((parseEnum.getJudgeValue() != null && !parseEnum.getJudgeValue().equals(re.getString(parseEnum.getJudgeField())))) {
            res.setMsg(re.getString(parseEnum.getMsg()));
            return res;
        }

        try {
            String[] dataField = parseEnum.getDataField();
            JSONObject result = re;
            for (int i = 0; i < dataField.length; i++) {
                if (i == dataField.length - 1) {
                    res.setObj(result.getObject(dataField[i], clazz));
                } else {
                    result = result.getJSONObject(dataField[i]);
                }
                if (result == null) {
                    break;
                }
            }
        } catch (Exception e) {
            log.error("parseReObj fail re:{} dataField:{} error:", re, parseEnum.getDataField(), e);
        }
        return res;
    }

    private static <T> List<T> parseReList(JSONObject re, @NotNull Class<T> clazz, String judgeField, @NotNull String judgeValue, String dataField) {
        if (re == null || (judgeValue != null && !judgeValue.equals(re.getString(judgeField))) || re.get(dataField) == null) {
            return Collections.emptyList();
        }
        try {
            return re.getJSONArray(dataField).toJavaList(clazz);
        } catch (Exception e) {
            log.error("parseReList fail re:{} dataField:{} error:", re, dataField, e);
        }
        return Collections.emptyList();
    }

    private static <T> List<T> parseReList(JSONObject re, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        if (re == null || (parseEnum.getJudgeValue() != null && !parseEnum.getJudgeValue().equals(re.getString(parseEnum.getJudgeField())))) {
            return Collections.emptyList();
        }
        try {
            String[] dataField = parseEnum.getDataField();
            JSONObject result = re;
            for (int i = 0; i < dataField.length; i++) {
                if (i == dataField.length - 1) {
                    List<T> ts = result.getJSONArray(dataField[i]).toJavaList(clazz);
                    return ts == null ? Collections.emptyList() : ts;
                } else {
                    result = result.getJSONObject(dataField[i]);
                }
                if (result == null) {
                    break;
                }
            }
        } catch (Exception e) {
            log.error("parseReList fail re:{} dataField:{} error:", re, parseEnum.getDataField(), e);
        }
        return Collections.emptyList();
    }


    private static <T> HttpRes<T> parseReListMsg(JSONObject re, @NotNull Class<T> clazz, HttpParseEnum parseEnum) {
        HttpRes<T> res = new HttpRes<>();
        res.setObjs(Collections.emptyList());
        if (re == null) {
            return res;
        }
        if ((parseEnum.getJudgeValue() != null && !parseEnum.getJudgeValue().equals(re.getString(parseEnum.getJudgeField())))) {
            res.setMsg(re.getString(parseEnum.getMsg()));
            return res;
        }
        try {
            res.setTotal(re.getInteger(parseEnum.getTotal()));
            String[] dataField = parseEnum.getDataField();
            JSONObject result = re;
            for (int i = 0; i < dataField.length; i++) {
                if (i == dataField.length - 1) {
                    List<T> ts = result.getJSONArray(dataField[i]).toJavaList(clazz);
                    if (ts != null) {
                        res.setObjs(ts);
                    }
                } else {
                    result = result.getJSONObject(dataField[i]);
                }
                if (result == null) {
                    break;
                }
            }
        } catch (Exception e) {
            log.error("parseReList fail re:{} dataField:{} error:", re, parseEnum.getDataField(), e);
        }
        return res;
    }


}
